package nanfang.nanf.DBUtil;

import java.sql.*;

public class DButil {

private static final String URL = "jdbc:mysql://127.0.0.1:3306/jdbc_test?useUnicode=true;characterEncoding=utf8;serverTimezone=Asia/Shanghai";
        private static final String DRIVER ="com.mysql.cj.jdbc.Driver";
        private static final String USER = "root";
        private static final String PASS = "root";

        static {
            try {
                Class.forName(DRIVER);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }

        public static Connection getConnection(){
            try {
                return DriverManager.getConnection(URL,USER,PASS);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        public static void close(ResultSet rst, Statement stmt, Connection conn){
            if(rst != null){
                try {
                    rst.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
            if(stmt != null){
                try {
                    stmt.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
            if(conn !=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        public static void main(String[] args) {
            System.out.println("连接成功"+getConnection());
        }
    }

